package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.SellBean;
import com.project.bean.UserBean;
import com.project.service.ISellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("sell")
public class SellController {
    @Autowired
    private ISellService sellService;

    @RequestMapping("add")
    public String add(HttpServletRequest req, SellBean sell) {
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        sellService.add(user.getId(), sell);
        return "ok";
    }

    @RequestMapping("findById")
    public SellBean findById(Integer id) {
        return sellService.findById(id);
    }

    @RequestMapping("findByItem")
    public IPage<SellBean> findByItem(String name, LocalDate startDate, LocalDate endDate, Integer pageNO) {
        return sellService.findByItem(pageNO, name, endDate, startDate);
    }
}
